import { app } from "electron";
import { join } from "path";
import { PATH } from "../utils";
import fs from "fs";

export const taskNameGenerator = async (SN, taskType) => {
  const time = new Date()
    .toLocaleString()
    .replaceAll("/", "_")
    .replaceAll(" ", "_")
    .replaceAll(":", "_");
  SN = SN.replaceAll(":", "_");
  const dataRootPath=PATH.dataPath;
  if(!fs.existsSync(dataRootPath)){
    if(!fs.existsSync(`D:\\ProgramData`)){
      fs.mkdirSync(`D:\\ProgramData`)
    }
    fs.mkdirSync(dataRootPath);
  }
  let path = join(dataRootPath, SN);
  console.log("path: " + path);
  let taskName = "TASK-" + taskType + "-" + time;
  const localPath = join(path, taskName);
  console.log("localPath: " + localPath);
  if (!fs.existsSync(localPath)) {
    if (!fs.existsSync(path)) {
      fs.mkdirSync(path);
    }
    fs.mkdirSync(localPath);
  }
  console.log("localPath: " + localPath);
  console.log("taskName: " + taskName);
  return taskName;
};
